package com.hunray.rent.security;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import com.hunray.rent.dao.IUserDao;
import com.hunray.rent.entity.User;

public class SysUserFilter extends PathMatchingFilter {

    @Autowired
    private IUserDao userDao;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue)
            throws Exception {

        String username = (String) SecurityUtils.getSubject().getPrincipal();
        User user = userDao.findByUsername(username);
        request.setAttribute("CURRENT_USER", user);
        return true;
    }
}